#ifndef IO_FLT_SIG_H_
#define IO_FLT_SIG_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "stdint.h"
#include "mytype.h"

#define io_read(_sig_, _p_, _s0_) ((_p_) ? (((_p_) == 1) ? (!!(_sig_)) : (!(_sig_))) : (_s0_))

	struct in_switch_st_struct
	{
		uint8_t time_pulse;	  
		uint8_t sample_pulse; 
		uint8_t val;
		uint8_t old;
		uint8_t found_edge;
		uint8_t lost_edge;
		uint8_t sample_old;
		uint8_t sample_keep_cnt; 
		uint32_t found_time_cnt; 
		uint32_t lost_time_cnt;	 
	};

	typedef struct in_switch_st_struct in_switch_st_type;

	struct simp_switch_st_struct
	{
		uint8_t time_pulse : 1;	  
		uint8_t sample_pulse : 1; 
		uint8_t val : 1;
		uint8_t old : 1;
		uint8_t found_edge : 1;
		uint8_t lost_edge : 1;
		uint8_t sample_old : 1;

		uint8_t sample_keep_cnt; 
		uint16_t found_time_cnt; 
		uint16_t lost_time_cnt;	 
	}; 

	typedef struct simp_switch_st_struct simp_switch_st_type;

	void in_switch_handle(in_switch_st_type *swobj, uint8_t sw_now);	 
	void simp_switch_handle(simp_switch_st_type *swobj, uint8_t sw_now); 

	struct io_asymmetric_flt_stuct
	{
		uint8_t st;			 
		int8_t flt_cnt;		 
		int8_t sv_lost_val;	 
		int8_t sv_fount_val; 
		int8_t sv_cnt_rang;	 
	};

	typedef struct io_asymmetric_flt_stuct io_asymmetric_flt_type;

	uint8_t io_asymmetric_flt(io_asymmetric_flt_type *io_obj, uint8_t st_now);

	struct io_flt_stuct
	{
		uint8_t st;		
		int8_t flt_cnt; 
	};

	typedef struct io_flt_stuct io_flt_type;

	uint8_t io_flt(io_flt_type *io_obj, int8_t flt_sv, uint8_t st_now);

	struct io_flt_edge_struct
	{
		uint8_t val : 1; 
		uint8_t old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;

		int8_t flt_cnt; 
	};

	typedef struct io_flt_edge_struct io_flt_edge_type;

	uint8_t io_flt_edge(io_flt_edge_type *io_obj, uint8_t flt_pulse, int8_t flt_sv, uint8_t st_now);

	struct io_flt_ext_struct
	{
		uint8_t val : 1; 
		uint8_t old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;
		uint8_t pulse_sample : 1; 
		uint8_t pulse_time : 1;	  

		int8_t flt_cnt; 
		uint16_t found_time_cnt;
		uint16_t lost_time_cnt;
	};

	typedef struct io_flt_ext_struct io_flt_ext_type;

	uint8_t io_flt_ext(io_flt_ext_type *io_obj, int8_t flt_sv, uint8_t st_now);

	struct io_flt_extv2_struct
	{
		uint8_t val : 1; 
		uint8_t old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;

		int8_t flt_cnt; 
		uint16_t found_time_cnt;
		uint16_t lost_time_cnt;
	};

	typedef struct io_flt_extv2_struct io_flt_extv2_type;

	struct io_flt_extv3_struct
	{
		uint8_t val : 1; 
		uint8_t old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;

		uint8_t lost_keep_sv, found_keep_sv; 
		uint8_t lost_keep_cnt, found_keep_cnt;
		int8_t flt_cnt; 
		uint16_t found_time_cnt;
		uint16_t lost_time_cnt;
	};

	typedef struct io_flt_extv3_struct io_flt_extv3_type;

	uint8_t io_flt_extv2(io_flt_extv2_type *io_obj, uint8_t flt_pulse, uint8_t time_pulse, int8_t flt_sv, uint8_t st_now); 
	uint8_t io_flt_extv3(io_flt_extv3_type *io_obj, uint8_t flt_pulse, uint8_t time_pulse, int8_t flt_sv, uint8_t st_now); 

	struct io_stcnt_flt_struct
	{
		uint8_t val : 1;
		uint8_t val_old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;

		uint16_t keep_cnt;
		uint32_t stlist;
	};

	typedef struct io_stcnt_flt_struct io_stcnt_flt_type;

	struct io_mstcnt_flt_struct
	{
		uint8_t val : 1;
		uint8_t val_old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;

		uint16_t keep_cnt;
		uint32_t stlist[4];
	};

	typedef struct io_mstcnt_flt_struct io_mstcnt_flt_type;

	void io_stcnt_flt_sample(io_stcnt_flt_type *obj, uint8_t st_now);
	uint8_t io_stcnt_flt_handle(io_stcnt_flt_type *obj, uint8_t tm_pulse, uint8_t flt_sv, uint8_t en_sv, uint8_t dis_sv);
	uint8_t io_stcnt_flt(io_stcnt_flt_type *obj, uint8_t flt_pulse, uint8_t flt_sv, uint8_t en_sv, uint8_t dis_sv, uint8_t st_now);

	void io_mstcnt_flt_sample(io_mstcnt_flt_type *obj, uint8_t st_now);
	uint8_t io_mstcnt_flt_handle(io_mstcnt_flt_type *obj, uint8_t tm_pulse, uint8_t flt_sv, uint8_t en_sv, uint8_t dis_sv);
	uint8_t io_mstcnt_flt(io_mstcnt_flt_type *obj, uint8_t flt_pulse, uint8_t flt_sv, uint8_t en_sv, uint8_t dis_sv, uint8_t st_now);

	struct io_flt_dlt_struct
	{
		uint8_t val : 1; 
		uint8_t old : 1;
		uint8_t edge : 1;
		uint8_t edge_found : 1;
		uint8_t edge_lost : 1;
		uint8_t pulse_sample : 1; 
		uint8_t pulse_time : 1;	  
		uint8_t flt_val : 1;	  

		int8_t flt_cnt;		 
		uint8_t act_dly_cnt; 
		uint8_t dis_dly_cnt; 
		uint8_t act_dly_sv;	 
		uint8_t dis_dly_sv;	 
		uint16_t found_time_cnt;
		uint16_t lost_time_cnt;
	};

	typedef struct io_flt_dlt_struct io_flt_dly_type;

	uint8_t io_flt_dly(io_flt_dly_type *io_obj, int8_t flt_sv, uint8_t st_now);
	uint8_t io_flt_dly_no_edge(io_flt_dly_type *io_obj, int8_t flt_sv, uint8_t st_now); 
	uint8_t io_flt_dly_no_time(io_flt_dly_type *io_obj, int8_t flt_sv, uint8_t st_now); 
	uint8_t io_flt_dly_simp(io_flt_dly_type *io_obj, int8_t flt_sv, uint8_t st_now);	

#ifdef __cplusplus
}
#endif

#endif 
